package com.handpay.nocardpay.baselibrary.main.home.view.fragment;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.bill.view.BillFragment;
import com.handpay.nocardpay.baselibrary.commbase.BaseProtocolKey;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.config.NoCardPayConfig;
import com.handpay.nocardpay.baselibrary.config.SecureManager;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;

import com.handpay.nocardpay.baselibrary.main.home.model.bean.LowestAccountTransferAmount;
import com.handpay.nocardpay.baselibrary.main.home.model.bean.PaymentTypeListBean;
import com.handpay.nocardpay.baselibrary.main.home.presenter.LowestPresenterImpl;
import com.handpay.nocardpay.baselibrary.main.home.presenter.PaymentTypeListPresenter;
import com.handpay.nocardpay.baselibrary.main.home.view.IHomeView;
import com.handpay.nocardpay.baselibrary.main.mine.MainFragment;
import com.handpay.nocardpay.baselibrary.main.mine.view.IICertNoExporyView;
import com.handpay.nocardpay.baselibrary.main.widget.IconBaseAdapter;
import com.handpay.nocardpay.baselibrary.main.widget.IconBaseOnItemClickListener;
import com.handpay.nocardpay.baselibrary.main.widget.NumImageView;
import com.handpay.nocardpay.baselibrary.main.widget.PayChannelInfo;
import com.handpay.nocardpay.baselibrary.notification.push.NoticeListener;
import com.handpay.nocardpay.baselibrary.notification.push.NoticePushFactory;
import com.handpay.nocardpay.baselibrary.notification.view.activity.NoticeActivity;
import com.handpay.nocardpay.baselibrary.onlinemarket.view.fragment.OnlineMarketFragment;
import com.handpay.nocardpay.baselibrary.pay.activity.QrCodePayActivity;
import com.handpay.nocardpay.baselibrary.pay.qrcodepay.view.fragment.QrCodePayFragment;
import com.handpay.nocardpay.baselibrary.pay.uniopayquick.view.UnionPayQuickFragment;
import com.handpay.nocardpay.baselibrary.pay.unipay.view.fragment.NoCardPayFragment;
import com.handpay.nocardpay.baselibrary.qualificationinfo.model.bean.QueryCertNoExporyBean;
import com.handpay.nocardpay.baselibrary.qualificationinfo.presenter.QualificationPresenterImpl;
import com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment.IDCardSupplementFragment;
import com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment.QualificationStatuInfoFragment;
import com.handpay.nocardpay.baselibrary.setting.view.fragment.GestureLockSettingFragment;
import com.handpay.nocardpay.baselibrary.utils.AccountUtils;
import com.handpay.nocardpay.baselibrary.utils.ArithUtil;
import com.handpay.nocardpay.baselibrary.utils.ClientEngine;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;
import com.handpay.nocardpay.baselibrary.utils.DialogUtils;
import com.handpay.nocardpay.baselibrary.utils.NoCardPayConstant;
import com.handpay.nocardpay.baselibrary.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import me.yokeyword.fragmentation.ISupportFragment;


/**
 * Created by sxshi on 2017/8/9.
 */

public class HomeFragment extends BaseFragment implements View.OnClickListener, NoticeListener, IHomeView, IICertNoExporyView {
    private Toolbar mToolbar;
    private GridView myGridView;
    private TextView mInputMoneyEditText;
    private IconBaseOnItemClickListener mItemClickListener;
    private ImageView home_select_pay_channel_iv;
    private PayChannelInfo mPayChannelInfo;
    private ArrayList<String> mPayChannelData;
    private LowestAccountTransferAmount mLowestAccountTransferAmount;
    private Double selectAmount = 0d;
    private QualificationPresenterImpl qualificationPresenter = null;
    static double MIN_AMOUNT = 1000;
    /**
     * 记录当前输入金额的字符串。通过CommonUtils.formatMoney设置到mInputMoneyet
     */
    private String mMoneyText;
    /**
     * 获取最低限额
     */
    private LowestPresenterImpl mLowestPresenter;
    private PaymentTypeListPresenter mPaymentTypeListPresenter;
    private int showTipCount = 0;//主要用于标志是否第一次显示
    private boolean bFirstLoadPayTypeData = true;//是否第一次加载支付方式数据
    private IconBaseAdapter mIconBaseAdapter;

    //红店商城
//    private ImageView btn_online_market;

    public static HomeFragment newInstance() {
        Bundle args = new Bundle();
        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_main_home;
    }

    @Override
    public void initView(View view) {
        mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        myGridView = (GridView) view.findViewById(R.id.all_gw);
        home_select_pay_channel_iv = (ImageView) view.findViewById(R.id.home_select_pay_channel_iv);

        mPayChannelData = new ArrayList<String>();
        initToolbar(mToolbar, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((MainFragment) getParentFragment()).start(BillFragment.newInstance());
            }
        }, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(_mActivity, NoticeActivity.class));
            }
        });
        mToolbar.setNavigationIcon(R.drawable.home_icon_left);
        mIconBaseAdapter = new IconBaseAdapter(this.getContext());
        mPayChannelData.add(PayChannelInfo.UNIPAY_CODE);
        mPayChannelData.add(PayChannelInfo.ALIPAY_CODE);
        mPayChannelData.add(PayChannelInfo.WECHATPAY_CODE);
        mPayChannelData.add(PayChannelInfo.UNIPAY_QUICK_CODE);

        mPayChannelData.add(PayChannelInfo.QQ_PAY_CODE);
        mPayChannelData.add(PayChannelInfo.JD_PAY_CODE);
        mPayChannelData.add(PayChannelInfo.UNIPAY_SCANNER_CODE);
        mPayChannelData.add(PayChannelInfo.QUICK_PASS_CODE);
        mIconBaseAdapter.setData(mPayChannelData);

        mPayChannelInfo = PayChannelInfo.getPayChannelInfos().get(mPayChannelData.get(0));
        mPayChannelInfo.isSelected = true;
        home_select_pay_channel_iv.setImageResource(mPayChannelInfo.iconResId[0]);  //金额框图标Icon显示联动
        myGridView.setAdapter(mIconBaseAdapter);
        mItemClickListener = new IconBaseOnItemClickListener(_mActivity.getApplicationContext()) {
            @Override
            public void gridViewItemOnclick(String tag) {
                HashMap<String, PayChannelInfo> maps = PayChannelInfo.getPayChannelInfos();
                if (maps.get(tag).isEnable) {
                    mPayChannelInfo = maps.get(tag);
                    PayChannelInfo.setPayChannelInfoSelectByTag(tag);
                    mIconBaseAdapter.notifyDataSetChanged();
                    //金额框图标Icon显示联动
                    home_select_pay_channel_iv.setImageResource(mPayChannelInfo.iconResId[0]);
                }
            }
        };
        myGridView.setOnItemClickListener(mItemClickListener);
        mInputMoneyEditText = (TextView) view.findViewById(R.id.rf_tv_input_amount);
        view.findViewById(R.id.rf_hpKbNum1).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum2).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum3).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum4).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum5).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum6).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum7).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum8).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum9).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum0).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbNum00).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbCancle).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbOk).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbDot).setOnClickListener(this);
        view.findViewById(R.id.rf_hpKbCancle).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                restZero();
                return true;
            }
        });
//        btn_online_market = (ImageView) view.findViewById(R.id.btn_online_market);
    }

    private void doPaymentTypeList(List<PaymentTypeListBean.ListBean> showChannelList) {
        //初始化全部不选中
        Iterator<String> it = mPayChannelData.iterator();
        while (it.hasNext()) {
            PayChannelInfo info = PayChannelInfo.getPayChannelInfos().get(it.next());
            info.isEnable = false;
            info.isSelected = false;
        }
        //不是第一次加载
        if (!bFirstLoadPayTypeData) {
            String lastPayChannelKey = mPayChannelInfo.itemId;
            mPayChannelInfo = null;
            for (int i = 0; i < showChannelList.size(); i++) {
                String key = String.valueOf(showChannelList.get(i).getPaymentType());
                PayChannelInfo info = PayChannelInfo.getPayChannelInfos().get(key);
                if (info != null) {
                    info.isEnable = true;
                    if (lastPayChannelKey.equals(key)) {
                        mPayChannelInfo = PayChannelInfo.getPayChannelInfos().get(key);
                        home_select_pay_channel_iv.setImageResource(mPayChannelInfo.iconResId[0]);  //金额框图标Icon显示联动
                        info.isSelected = true;
                    }
                    mPayChannelData.remove(key);
                    mPayChannelData.add(i, key);
                }
            }
        } else {
            bFirstLoadPayTypeData = false;
            mPayChannelInfo = null;
            for (int i = 0; i < showChannelList.size(); i++) {
                String key = String.valueOf(showChannelList.get(i).getPaymentType());
                PayChannelInfo info = PayChannelInfo.getPayChannelInfos().get(key);
                if (info != null) {
                    info.isEnable = true;
                    mPayChannelData.remove(key);
                    mPayChannelData.add(i, key);
                }
            }
        }
        if (mPayChannelInfo == null) {
            String key = String.valueOf(showChannelList.get(0).getPaymentType());
            mPayChannelInfo = PayChannelInfo.getPayChannelInfos().get(key);
            home_select_pay_channel_iv.setImageResource(mPayChannelInfo.iconResId[0]);    //金额框图标Icon显示联动
            PayChannelInfo info = PayChannelInfo.getPayChannelInfos().get(key);
            info.isSelected = true;
        }
        mIconBaseAdapter.notifyDataSetChanged();
    }

    @Override
    public void initListener() {
//        btn_online_market.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.NOUPLOAD) {
//                    DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.dialog_title), _mActivity.getString(R.string.home_online_market_no_submit_qualification), _mActivity.getString(R.string.home_online_market_dialog_cancel), new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    }, _mActivity.getString(R.string.home_online_market_dialog_ok), new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            ((MainFragment) getParentFragment()).start(QualificationStatuInfoFragment.newInstance());
//                        }
//                    });
//                } else {
//                    double minAmount = MIN_AMOUNT;
//                    if (mLowestAccountTransferAmount != null) {
//                        minAmount = mLowestAccountTransferAmount.getUnionPayOnlineAmount();
//                    }
//                    ((MainFragment) getParentFragment()).start(OnlineMarketFragment.newInstance(minAmount));
//                }
//            }
//        });
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        //最低限额
        mLowestPresenter = new LowestPresenterImpl(this, _mActivity);
        mPaymentTypeListPresenter = new PaymentTypeListPresenter(this, _mActivity);
        queryLowestAmount();
        qualificationPresenter = new QualificationPresenterImpl(_mActivity, this);
        restZero();
        queryPaymentTypeList();
        if (AccountUtils.AccountStatus.NOUPLOAD == AccountUtils.getAccountStatus(_mActivity)) {
            ((MainFragment) getParentFragment()).start(LoginSuccessNouploadQuaFragment.newInstance());
        }

        NoticePushFactory.with().registerNoticeListener(this);

//        if (checkIsShowGuideSmartPayView()) {
//            return;
//        }

        /**
         * 1、初始化首次登录手势密码第一次提醒标记
         * 2、手势密码、有效期是否过期
         */
        ClientEngine.getInstance().removeGlobal(NoCardPayConstant.GESTURE_PWD_SETTING_REMIND_TIPS_HOME_VIEW);
        checkGesturePWDAndExpiry();
    }

//    /**
//     * 审核通过并且智能还款开关打开用户显示智能还款按钮
//     */
//    private boolean checkIsShowGuideSmartPayView() {
//        if ((int) ClientEngine.getInstance().getGlobal(NoCardPayConstant.SHOWCRDITPAGE) == NoCardPayConstant.CREDITPAGE_VISIBITY && AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.SUCCESS) {
//
//            ((MainFragment) getParentFragment()).addSmartView();
//            /**
//             *首次显示智能还款并弹出引导页用户不做后面的手势密码和身份证有效期判断
//             */
//            if (PreferenceManager.getInstance(_mActivity).getBoolean(NoCardPayConstant.SMART_PAY_TIPS_SHOW_MAIN_VIEW, true)) {
//                return true;
//            }
//        } else {
//            ((MainFragment) getParentFragment()).removeView();
//        }
//        return false;
//    }


    /**
     * 提交资质用户检查是否设置手势密码，如果审核通过并且已有手势密码就直接判断有效期是否过期
     */
    private void checkGesturePWDAndExpiry() {
        /**
         *未提交资质直接退出
         */
        if (AccountUtils.getAccountStatus(_mActivity) != AccountUtils.AccountStatus.NOUPLOAD) {
            if (TextUtils.isEmpty(ClientEngine.getInstance().getRMSData(BaseProtocolKey.KEY_GESTURE_PWD)) && NoCardPayConfig.isNoCardPay != NoCardPayConstant.FASTBILL) {
                boolean bShowDialog = (boolean) ClientEngine.getInstance().getGlobal(NoCardPayConstant.GESTURE_PWD_SETTING_REMIND_TIPS_HOME_VIEW, true);
                if (bShowDialog) {
                    showIsSettingGesturePWDDialog();
                    return;
                }
            }
            if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.SUCCESS) {//审核通过
                queryCertNoExpiry();
            }
        }
    }

    private void showIsSettingGesturePWDDialog() {
        if (_mActivity != null) {
            ClientEngine.getInstance().saveGlobal(NoCardPayConstant.GESTURE_PWD_SETTING_REMIND_TIPS_HOME_VIEW, false);
            DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.tip), _mActivity.getString(R.string.home_setting_gesture_pwd_tips), _mActivity.getString(R.string.home_setting_gesture_pwd_tips_setting), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ((MainFragment) getParentFragment()).start(GestureLockSettingFragment.newInstance());
                }
            }, _mActivity.getString(R.string.home_setting_gesture_pwd_tips_ikonew), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        }
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        HPLog.i(HPLog.YL_TAG, "onSupportVisible:");
        StatusBarUtil.setColor(_mActivity, _mActivity.getResources().getColor(R.color.colorPrimaryDark), 0);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        HPLog.i(HPLog.YL_TAG, "onHiddenChanged:" + hidden);
        if (!hidden) {
            queryPaymentTypeList();
            restZero();
//            //如果显示引导框就不做下面有效期检查
//            if (checkIsShowGuideSmartPayView()) {
//                return;
//            }
            /**
             * 手势密码、有效期是否过期
             */
            checkGesturePWDAndExpiry();
        }
    }

    private void queryLowestAmount() {
        HashMap<String, Object> paramers = new HashMap<String, Object>();
        paramers.put("version", ClientEngine.getInstance().VERSION);
        paramers.put("platform", ClientEngine.getInstance().MOBILE_TYPE);
        paramers.put("channel", ClientEngine.getInstance().CHANNEL);
        mLowestPresenter.getLowestAccountTransferAmount(paramers, LowestAccountTransferAmount.class, false);
    }

    private void queryPaymentTypeList() {
        HPLog.i(HPLog.YL_TAG, "queryPaymentTypeList:");
        HashMap<String, Object> paramers = new HashMap<String, Object>();
        paramers.put(BaseProtocolKey.CLIENTCHANNEL, ClientEngine.getInstance().CLIENTCHANNEL);
        paramers.put(BaseProtocolKey.CHANNEL, ClientEngine.getInstance().CHANNEL);
        mPaymentTypeListPresenter.getPaymentTypeList(paramers, PaymentTypeListBean.class, false);
    }

    @Override
    public String getFragmentTitle() {
        return _mActivity.getString(R.string.home);
    }

    @Override
    public void onClick(View v) {
        char c;
        int i = v.getId();
        if (i == R.id.rf_hpKbNum1) {
            c = '1';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum2) {
            c = '2';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum3) {
            c = '3';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum4) {
            c = '4';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum5) {
            c = '5';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum6) {
            c = '6';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum7) {
            c = '7';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum8) {
            c = '8';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum9) {
            c = '9';
            moneyText(dealInput(c));

        } else if (i == R.id.rf_hpKbNum0) {
            c = '0';
            moneyText(dealInput(c));
        } else if (i == R.id.rf_hpKbNum00) {
            c = '0';
            moneyText(dealInput(c));
            moneyText(dealInput(c));
        } else if (i == R.id.rf_hpKbDot) {
            c = '.';
            moneyText(dealInput(c));
        } else if (i == R.id.rf_hpKbCancle) {
            c = '-';
            moneyText(dealInput(c));
        } else if (i == R.id.rf_hpKbOk) {
            selectAmount = Double.valueOf(mMoneyText);
            if (selectAmount == 0) {
                Toast.makeText(_mActivity, _mActivity.getString(R.string.please_input_no_card_pay_alert), Toast.LENGTH_SHORT).show();
                return;
            }

            if (mPayChannelInfo.itemId.equals(PayChannelInfo.ALIPAY_CODE)) {
                //支付宝正扫
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getAliScanpayAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }
                checkUserStatus(QrCodePayActivity.class, PayChannelInfo.ALIPAY_CODE, ArithUtil.mul(selectAmount, 100d));
            } else if (mPayChannelInfo.itemId.equals(PayChannelInfo.WECHATPAY_CODE)) {
                //微信正扫
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getWechatScanpayAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }
                checkUserStatus(QrCodePayActivity.class, PayChannelInfo.WECHATPAY_CODE, ArithUtil.mul(selectAmount, 100d));

            } else if (mPayChannelInfo.itemId.equals(PayChannelInfo.UNIPAY_CODE)) {
                //银联支付、银联在线
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getUnionPayOnlineAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }
                checkUserStatus(NoCardPayFragment.newInstance(ArithUtil.mul(selectAmount, 100d)));
            } else if (mPayChannelInfo.itemId.equals(PayChannelInfo.UNIPAY_QUICK_CODE)) {
                //银联快捷
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getUnionPayQuickAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }

                checkUserStatus(UnionPayQuickFragment.newInstance(ArithUtil.mul(selectAmount, 100d), NoCardPayConstant.TRADETYPE_UNIONPAYQUICK));
            } else if (mPayChannelInfo.itemId.equals(PayChannelInfo.UNIPAY_SCANNER_CODE)) {
                //银联二维码
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getUnionScanpayAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }
                checkUserStatus(QrCodePayActivity.class, PayChannelInfo.UNIPAY_SCANNER_CODE, ArithUtil.mul(selectAmount, 100d));
            } else if (mPayChannelInfo.itemId.equals(PayChannelInfo.QQ_PAY_CODE)) {
                //qq钱包
                double minAmount = MIN_AMOUNT;
                if (mLowestAccountTransferAmount != null) {
                    minAmount = mLowestAccountTransferAmount.getQqScanpayAmount();
                }
                if (ArithUtil.mul(selectAmount, 100d) < minAmount) {
                    Toast.makeText(_mActivity, _mActivity.getString(R.string.min_no_card_pay_alert, minAmount / 100), Toast.LENGTH_SHORT).show();
                    return;
                }
                checkUserStatus(QrCodePayActivity.class, PayChannelInfo.QQ_PAY_CODE, ArithUtil.mul(selectAmount, 100d));
            } else {
                DialogUtils.showToast(_mActivity, getString(R.string.please_update_new_version_alert));
            }
        }
    }

    protected void restZero() {
        SpannableString msp = new SpannableString("0.00");
//        msp.setSpan(new RelativeSizeSpan(0.5f), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mInputMoneyEditText.setText(msp);
        mMoneyText = NoCardPayConstant.MONEY_ZERO;
    }

    /**
     * 查询证件状态(只有资质审核通过后才需要发起
     */
    private void queryCertNoExpiry() {
        HPLog.i(HPLog.LFP_TAG, "MineFragment::queryCertNoExpiry::start");
        HashMap<String, Object> params = new HashMap<>();
        params.put(BaseProtocolKey.ACCOUNT, SecureManager.getInstance().des(AccountUtils.getAccountName(_mActivity), 1, null));
        if (qualificationPresenter != null) {
            qualificationPresenter.queryCertNoExpory(params, false);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        NoticePushFactory.with().unregisterNoticeListener(this);
        PayChannelInfo.release();
    }

    private void moneyText(String money) {
        mMoneyText = money;
        String temp_money = money;
        SpannableString msp = new SpannableString(CommonUtils.formatMoneyWithSplite(Double.parseDouble(temp_money)));
        mInputMoneyEditText.setText(msp);
    }

    private String dealInput(char c) {
        String money = mMoneyText;
        // 如果输入删除
        if ('-' == c) {
            if (NoCardPayConstant.MONEY_ZERO.equals(money) || money.length() == 1) {
                return NoCardPayConstant.MONEY_ZERO;
            }
            if ('.' == money.charAt(money.length() - 1)) {
                if (2 == money.length()) {
                    return NoCardPayConstant.MONEY_ZERO;
                } else {
                    return money.substring(0, money.length() - 2);
                }
            }
            return money.substring(0, money.length() - 1);
        }

        int indexOfDot = money.indexOf(".");
        // 如果当前没有输入小数点，且要输入的不是小数点的时候
        if (-1 == indexOfDot && '.' != c) {
            if (money.length() >= NoCardPayConstant.MONEY_MAX_LEN) {
                return money;
            }
        }
        // 如果遇到输入0。注意输入00.相当于调用两次输入0
        if ('0' == c) {
            if (NoCardPayConstant.MONEY_ZERO.equals(money)) {
                return NoCardPayConstant.MONEY_ZERO;
            }
            // 如果没有小数点，或者没有输入到小数点后两位，仍然可以输入
            if (indexOfDot == -1 || indexOfDot >= (money.length() - 2)) {
                return money + c;
            }
        }
        // 如果遇到输入1~9
        if ('1' <= c && '9' >= c) {
            if (NoCardPayConstant.MONEY_ZERO.equals(money)) {
                return c + "";
            }
            // 如果没有小数点，或者没有输入到小数点后两位，仍然可以输入
            if (indexOfDot == -1 || indexOfDot >= (money.length() - 2)) {
                return money + c;
            }
        }
        // 如果遇到输入点
        if ('.' == c) {
            if (NoCardPayConstant.MONEY_ZERO.equals(money)) {
                return "0.";
            }
            // 如果当前money没有'.'
            if (!money.contains(".")) {
                return (money + ".");
            }
        }
        return money;
    }

    @Override
    public void setLowestAccountTransferAmount(LowestAccountTransferAmount response) {
        mLowestAccountTransferAmount = response;
        HPLog.i(HPLog.YL_TAG, "mLowestAccountTransferAmount:" + mLowestAccountTransferAmount.toString());
    }

    @Override
    public void setPaymentTypeList(PaymentTypeListBean response) {
        List<PaymentTypeListBean.ListBean> list = response.getList();
        List<PaymentTypeListBean.ListBean> showChannelList = new ArrayList<PaymentTypeListBean.ListBean>();
        //检查是否有不包含支付类型
        for (int i = 0; i < list.size(); i++) {
            String key = String.valueOf(list.get(i).getPaymentType());
            boolean bExist = PayChannelInfo.getPayChannelInfos().containsKey(key);
            if (bExist) {
                showChannelList.add(list.get(i));
            }
        }
        if (showChannelList.size() == 0) {
            return;
        }
        doPaymentTypeList(showChannelList);
    }

    @Override
    public void queryCertNoSuccess(QueryCertNoExporyBean queryCertNoExporyBean) {
        HPLog.i(HPLog.LFP_TAG, "MineFragment::queryCertNoSuccess::queryCertNoExporyBean=" + queryCertNoExporyBean.toString());
        String status = String.valueOf(queryCertNoExporyBean.getStatus());
        AccountUtils.setCertNoExporyStatus(_mActivity, status);
        //待补件/审核失败显示
        if (showTipCount == 0 && (AccountUtils.Account.CERTNO_NOSUPPLEMENT.equals(status) || AccountUtils.Account.CERTNO_FAIL.equals(status))) {
            String tipmsg = queryCertNoExporyBean.getRemindMessage();
            if (_mActivity != null) {
                DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.tip), tipmsg, _mActivity.getString(R.string.mine_go4submit), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ((MainFragment) getParentFragment()).start(IDCardSupplementFragment.newInstance());
                    }
                }, _mActivity.getString(R.string.mine_ikonew), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                showTipCount++;
            }
        }
    }

    @Override
    public void queryCertNoFail(String errorMsg) {
        DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.dialog_title), errorMsg, false);
    }

    /**
     * 检测用户状态【未提交-提示引导提交，失败或者审核中进入QualificationStatuInfoFragment】
     */
    private void checkUserStatus(ISupportFragment tagetFragment) {
        if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.NOUPLOAD) {
            DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.dialog_title), _mActivity.getString(R.string.no_submit_qualification), _mActivity.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }, _mActivity.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ((MainFragment) getParentFragment()).start(QualificationStatuInfoFragment.newInstance());
                }
            });
        } else {
            ((MainFragment) getParentFragment()).start(tagetFragment);
            restZero();
        }
    }

    /**
     * 检测用户状态【未提交-提示引导提交，失败或者审核中进入QualificationStatuInfoFragment】
     */
    private void checkUserStatus(Class<?> cls, String payType, double selectAmount) {
        if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.NOUPLOAD) {
            DialogUtils.showAlertDialog(_mActivity, _mActivity.getString(R.string.dialog_title), _mActivity.getString(R.string.no_submit_qualification), _mActivity.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }, _mActivity.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ((MainFragment) getParentFragment()).start(QualificationStatuInfoFragment.newInstance());
                }
            });
        } else {
            Intent intent = new Intent(_mActivity, cls);
            intent.putExtra(QrCodePayFragment.QR_CODE_PAY_TYPE, payType);
            intent.putExtra(QrCodePayFragment.AMOUNT_KEY, selectAmount);
            _mActivity.startActivity(intent);
            restZero();
        }
    }

    @Override
    public void detectedNotice(boolean flag) {
        NumImageView mNumImageView = (NumImageView) mToolbar.findViewById(R.id.iv_right);
        if (flag) {
            mNumImageView.setNum(1);
        } else {
            mNumImageView.setNum(0);
        }
    }

}